package com.axdoc.walletbiz.record.mq.service.impl;

import java.text.SimpleDateFormat;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.axdoc.walletbiz.record.mq.message.Message;
import com.axdoc.walletbiz.record.mq.message.PaySuccessMessage;
import com.axdoc.walletbiz.record.mq.service.MsgService;
import com.axdoc.walletbiz.record.service.RecordService;
/**
 * 支付成功-消息处理
 *
 */
@Component("paySuccessService")
public class PaySuccessServiceImpl implements MsgService {
	public static Logger logger = LoggerFactory.getLogger("listen_message");
	
	@Autowired
	private RecordService recordService;
	@Override
	public void handle(Message msg) {
		try {
			PaySuccessMessage message=(PaySuccessMessage) msg;
			logger.info("[处理支付成功消息,req,msg:"+message+" ]");
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			Long biz_time = StringUtils.isEmpty(message.getData().get("biz_time").toString())
					? System.currentTimeMillis() : Long.valueOf(message.getData().get("biz_time").toString());
			if(message.getData().get("biz_time2") != null){
				biz_time = sdf.parse(message.getData().get("biz_time2").toString()).getTime();
			}
			String trade_no=message.getData().get("trade_no").toString();
			//开始记账
			recordService.paySuccess(trade_no,biz_time, msg.getId());
		} catch (Exception e) {
			logger.error("[处理支付成功消息异常,error,msg:"+msg,e);
		}
	}
	
}
